package week2;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Day1 {
    //1.在字符串中找出连续最长的数字串
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String s = in.nextLine();
            int len=0;
            String str = "";
            int left=0,right=0;
            while(right<s.length()&&left<s.length()) {
                if(!(s.charAt(right)>='0'&&s.charAt(right)<='9')) {
                    right++;
                    left=right;
                }else {
                    StringBuilder sb = new StringBuilder();
                    sb.append(s.charAt(right));
                    right++;
                    while(right<s.length()&&s.charAt(right)>='0'&&s.charAt(right)<='9') {
                        sb.append(s.charAt(right));
                        right++;
                    }
                    String tmp = new String(sb);
                    if(right-left-1 > len) {
                        str=tmp;
                        len=right-left-1;
                    }
                    left=right;
                }
            }
            System.out.println(str);
        }
        in.close();
    }
    //2.岛屿数量
    boolean[][] c;
    int[] dx={0,0,1,-1};
    int[] dy={-1,1,0,0};
    int m,n;
    public int solve (char[][] grid) {
        m=grid.length;
        n=grid[0].length;
        c=new boolean[m][n];
        int count=0;
        for(int i=0;i<m;i++) {
            for(int j=0;j<n;j++) {
                if(grid[i][j]=='1'&&!c[i][j]) {

                    floodfill(grid,i,j);
                    count++;
                }
            }
        }
        return count;
    }
    public void floodfill(char[][] grid,int i,int j) {
        c[i][j]=true;
        for(int k=0;k<4;k++) {
            int x=i+dx[k];
            int y=j+dy[k];
            if(x>=0&&x<m&&y>=0&&y<n&&!c[x][y]&&grid[x][y]=='1') {
                floodfill(grid,x,y);
            }
        }
    }
    //3.拼三角
    static List<Integer> list1 = new ArrayList<>();//三角形1
    static List<Integer> list2 = new ArrayList<>();//三角形2
    static boolean[] check;
    public static void main3(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int t = in.nextInt();
            int[][] arr = new int[t][6];
            for(int i=0;i<t;i++) {
                for(int j=0;j<6;j++) {
                    arr[i][j]=in.nextInt();
                }
            }
            int c=0;
            check = new boolean[6];
            while(c < t) {
                boolean bool = dfs(arr,c,0);
                if(bool) System.out.println("Yes");
                else System.out.println("No");
                list1.clear();
                list2.clear();
                c++;
            }
        }
    }
    //递归每一行
    public static boolean dfs(int[][] ret,int m,int n) {
        if(list1.size()==3) {
            for(int i=0;i<6;i++) {
                if(!check[i]) {
                    list2.add(ret[m][i]);
                }
            }
            boolean x = isThree(list1);
            boolean y=false;
            if(list2.size()==3) {
                y= isThree(list2);
            }
            list2.clear();
            return x&&y;
        }
        for(int i=n;i<6;i++) {
            list1.add(ret[m][i]);
            check[i]=true;
            boolean bool = dfs(ret,m,i+1);
            //回溯
            if(bool) return true;
            list1.remove(list1.size()-1);
            check[i]=false;
        }
        return false;
    }
    //判断是否为三角形
    public static boolean isThree(List<Integer> list) {
        int a=list.get(0);
        int b=list.get(1);
        int c=list.get(2);
        if(a+b>c && a+c>b&&b+c>a&&a-b<c && c-a<b&&b-c<a) {
            return true;
        }
        return false;
    }
}
